


/*
'===============================================================================
'  HNG.Portal.BL.TblTienTeManagerBase
'===============================================================================
*/

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using HNG.Portal.BLL;
using HNG.Portal.DAL;
using HNG.Portal.DAL.EntityClasses;
using HNG.Portal.DAL.FactoryClasses;
using HNG.Portal.DAL.HelperClasses;
using SD.LLBLGen.Pro.ORMSupportClasses;
using System.Windows.Forms;
namespace HNG.Portal.BLL
{
	public class TblTienTeManagerBase
	{
	    
		#region ColumnNames
		
				public const String Field_Id="Id";
				
				public const String Field_LangId="LangId";
				
				public const String Field_Code="Code";
				
				public const String Field_Mota="Mota";
				
				public const String Field_TrangThai="TrangThai";
				
		#endregion	
		/// <summary>
		/// Purpose: Class constructor.
		/// </summary>
		public TblTienTeManagerBase()
		{
			// Nothing for now.
		}
		public DataTable Clone()
		{
			DataTable dt = new DataTable();
						
			
			dt.Columns.Add(Field_Id,typeof(int));
			
						
			
			dt.Columns.Add(Field_LangId,typeof(string));
			
						
			
			dt.Columns.Add(Field_Code,typeof(string));
			
						
			
			dt.Columns.Add(Field_Mota,typeof(string));
			
						
			
			dt.Columns.Add(Field_TrangThai,typeof(bool));
			
			            
            return dt;			
		}
			
		public TblTienTeEntity Convert_Entity(TblTienTeEntity _TblTienTeEntity,TblTienTeEntity _TblTienTeEntity_XML)
		{	
			
				
			_TblTienTeEntity.Id= _TblTienTeEntity_XML.Id;
				
			_TblTienTeEntity.LangId= _TblTienTeEntity_XML.LangId;
				
			_TblTienTeEntity.Code= _TblTienTeEntity_XML.Code;
				
			_TblTienTeEntity.Mota= _TblTienTeEntity_XML.Mota;
				
			_TblTienTeEntity.TrangThai= _TblTienTeEntity_XML.TrangThai;
				
			
			return _TblTienTeEntity;
		}	
		
			
		public void InsertCollection(EntityCollection _Collection)
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
            {
                adapter.SaveEntityCollection(_Collection);
            }
		}

		public TblTienTeEntity Insert(TblTienTeEntity TblTienTeEntity)
		{
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.SaveEntity(TblTienTeEntity, true);
			}
			return TblTienTeEntity;
		}

		
		public TblTienTeEntity Insert(int Id, string LangId, string Code, string Mota, bool TrangThai)
		{
			TblTienTeEntity _TblTienTeEntity = new TblTienTeEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblTienTeEntity.Id = Id;
				_TblTienTeEntity.LangId = LangId;
				_TblTienTeEntity.Code = Code;
				_TblTienTeEntity.Mota = Mota;
				_TblTienTeEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblTienTeEntity, true);
			}
			return _TblTienTeEntity;
		}

		public TblTienTeEntity Insert(string LangId, string Code, string Mota, bool TrangThai)
		{
			TblTienTeEntity _TblTienTeEntity = new TblTienTeEntity();
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				
				_TblTienTeEntity.LangId = LangId;
				_TblTienTeEntity.Code = Code;
				_TblTienTeEntity.Mota = Mota;
				_TblTienTeEntity.TrangThai = TrangThai;
				adapter.SaveEntity(_TblTienTeEntity, true);
			}
			return _TblTienTeEntity;
		}

		public bool Update(TblTienTeEntity _TblTienTeEntity)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				RelationPredicateBucket filter = new RelationPredicateBucket();
				IPredicateExpression _PredicateExpression = new PredicateExpression();
				_PredicateExpression.Add(TblTienTeFields.Id == _TblTienTeEntity.Id);
					
				filter.PredicateExpression.Add(_PredicateExpression);

				adapter.UpdateEntitiesDirectly(_TblTienTeEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}
		
		public bool Update(TblTienTeEntity _TblTienTeEntity, RelationPredicateBucket filter)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.UpdateEntitiesDirectly(_TblTienTeEntity, filter);
				toReturn = true;
			}
			return toReturn;
		}

		public bool Update(int Id, string LangId, string Code, string Mota, bool TrangThai)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblTienTeEntity _TblTienTeEntity = new TblTienTeEntity(Id);
				if (adapter.FetchEntity(_TblTienTeEntity))
				{
				
					_TblTienTeEntity.LangId = LangId;
					_TblTienTeEntity.Code = Code;
					_TblTienTeEntity.Mota = Mota;
					_TblTienTeEntity.TrangThai = TrangThai;
					adapter.SaveEntity(_TblTienTeEntity, true);
					toReturn = true;
				}
			}
			return toReturn;
		}

		public bool Delete(int Id)
		{
			bool toReturn = false;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblTienTeEntity _TblTienTeEntity = new TblTienTeEntity(Id);
				if (adapter.FetchEntity(_TblTienTeEntity))
				{
					adapter.DeleteEntity(_TblTienTeEntity);
					toReturn = true;
				}
			}
			return toReturn;
		}
		
		public void DeleteAll() 
		{
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.DeleteEntitiesDirectly("TblTienTeEntity", null);
			}
		}
		
		
		public int DeleteById(int Id)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblTienTeEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByLangId(string LangId)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblTienTeEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByCode(string Code)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.Code == Code);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblTienTeEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByMota(string Mota)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblTienTeEntity", filter);
			}
			return toReturn;
		}
		
		public int DeleteByTrangThai(bool TrangThai)
		{
			int toReturn = 0;
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				toReturn = adapter.DeleteEntitiesDirectly("TblTienTeEntity", filter);
			}
			return toReturn;
		}
		

		
		public TblTienTeEntity SelectOne(int Id)
		{
			TblTienTeEntity toReturn = null;
			using(DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				TblTienTeEntity _TblTienTeEntity = new TblTienTeEntity(Id);
				if (adapter.FetchEntity(_TblTienTeEntity))
				{
					toReturn = _TblTienTeEntity;
				}
			}
			return toReturn;
		}

		// Return EntityCollection
		public EntityCollection SelectAll()
		{
			EntityCollection _TblTienTeCollection = new EntityCollection( new TblTienTeEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblTienTeCollection, null, 0, null);
			}
			return _TblTienTeCollection;
		}
		
		// Return DataTable
		public DataTable SelectAllRDT()
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblTienTeCollection.EntityFactoryToUse.CreateFields(), toReturn, null, true);
			}
			return toReturn;
		}

		
		// Return EntityCollection
		public EntityCollection SelectById(int Id)
		{
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblTienTeCollection, filter, 0, null);
			}
			return _TblTienTeCollection;
		}
		
		// Return DataTable
		public DataTable SelectByIdRDT(int Id)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.Id == Id);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblTienTeCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByLangId(string LangId)
		{
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblTienTeCollection, filter, 0, null);
			}
			return _TblTienTeCollection;
		}
		
		// Return DataTable
		public DataTable SelectByLangIdRDT(string LangId)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.LangId == LangId);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblTienTeCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByCode(string Code)
		{
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.Code == Code);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblTienTeCollection, filter, 0, null);
			}
			return _TblTienTeCollection;
		}
		
		// Return DataTable
		public DataTable SelectByCodeRDT(string Code)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.Code == Code);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblTienTeCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByMota(string Mota)
		{
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblTienTeCollection, filter, 0, null);
			}
			return _TblTienTeCollection;
		}
		
		// Return DataTable
		public DataTable SelectByMotaRDT(string Mota)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.Mota == Mota);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblTienTeCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		// Return EntityCollection
		public EntityCollection SelectByTrangThai(bool TrangThai)
		{
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();

			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);
			
			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchEntityCollection(_TblTienTeCollection, filter, 0, null);
			}
			return _TblTienTeCollection;
		}
		
		// Return DataTable
		public DataTable SelectByTrangThaiRDT(bool TrangThai)
		{
			DataTable toReturn = new DataTable();
			EntityCollection _TblTienTeCollection = new EntityCollection(new TblTienTeEntityFactory());
			RelationPredicateBucket filter = new RelationPredicateBucket();
			
			IPredicateExpression _PredicateExpression = new PredicateExpression();
			_PredicateExpression.Add(TblTienTeFields.TrangThai == TrangThai);
			filter.PredicateExpression.Add(_PredicateExpression);

			using (DataAccessAdapterBase adapter = (new DataAccessAdapterFactory()).CreateAdapter())
			{
				adapter.FetchTypedList(_TblTienTeCollection.EntityFactoryToUse.CreateFields(), toReturn, filter, true);
			}
			return toReturn;
		}
		
		

	}
}
